\(\int (a+b \tan (e+f x))^2 (c+d \tan (e+f x)) \, dx\) [1192]

   Optimal result
   Rubi [A] (verified)
   Mathematica [C] (verified)
   Maple [A] (verified)
   Fricas [A] (verification not implemented)
   Sympy [A] (verification not implemented)
   Maxima [A] (verification not implemented)
   Giac [B] (verification not implemented)
   Mupad [B] (verification not implemented)

Optimal result

Integrand size = 23, antiderivative size = 87 \[ \int (a+b \tan (e+f x))^2 (c+d \tan (e+f x)) \, dx=\left (a^2 c-b^2 c-2 a b d\right ) x-\frac {\left (2 a b c+a^2 d-b^2 d\right ) \log (\cos (e+f x))}{f}+\frac {b (b c+a d) \tan (e+f x)}{f}+\frac {d (a+b \tan (e+f x))^2}{2 f} \]

[Out]

(a^2*c-2*a*b*d-b^2*c)*x-(a^2*d+2*a*b*c-b^2*d)*ln(cos(f*x+e))/f+b*(a*d+b*c)*tan(f*x+e)/f+1/2*d*(a+b*tan(f*x+e))
^2/f

Rubi [A] (verified)

Time = 0.09 (sec) , antiderivative size = 87, normalized size of antiderivative = 1.00, number of steps used = 3, number of rules used = 3, \(\frac {\text {number of rules}}{\text {integrand size}}\) = 0.130, Rules used = {3609, 3606, 3556} \[ \int (a+b \tan (e+f x))^2 (c+d \tan (e+f x)) \, dx=-\frac {\left (a^2 d+2 a b c-b^2 d\right ) \log (\cos (e+f x))}{f}+x \left (a^2 c-2 a b d-b^2 c\right )+\frac {b (a d+b c) \tan (e+f x)}{f}+\frac {d (a+b \tan (e+f x))^2}{2 f} \]

[In]

Int[(a + b*Tan[e + f*x])^2*(c + d*Tan[e + f*x]),x]

[Out]

(a^2*c - b^2*c - 2*a*b*d)*x - ((2*a*b*c + a^2*d - b^2*d)*Log[Cos[e + f*x]])/f + (b*(b*c + a*d)*Tan[e + f*x])/f
 + (d*(a + b*Tan[e + f*x])^2)/(2*f)

Rule 3556

Int[tan[(c_.) + (d_.)*(x_)], x_Symbol] :> Simp[-Log[RemoveContent[Cos[c + d*x], x]]/d, x] /; FreeQ[{c, d}, x]

Rule 3606

Int[((a_) + (b_.)*tan[(e_.) + (f_.)*(x_)])*((c_.) + (d_.)*tan[(e_.) + (f_.)*(x_)]), x_Symbol] :> Simp[(a*c - b
*d)*x, x] + (Dist[b*c + a*d, Int[Tan[e + f*x], x], x] + Simp[b*d*(Tan[e + f*x]/f), x]) /; FreeQ[{a, b, c, d, e
, f}, x] && NeQ[b*c - a*d, 0] && NeQ[b*c + a*d, 0]

Rule 3609

Int[((a_.) + (b_.)*tan[(e_.) + (f_.)*(x_)])^(m_)*((c_.) + (d_.)*tan[(e_.) + (f_.)*(x_)]), x_Symbol] :> Simp[d*
((a + b*Tan[e + f*x])^m/(f*m)), x] + Int[(a + b*Tan[e + f*x])^(m - 1)*Simp[a*c - b*d + (b*c + a*d)*Tan[e + f*x
], x], x] /; FreeQ[{a, b, c, d, e, f}, x] && NeQ[b*c - a*d, 0] && NeQ[a^2 + b^2, 0] && GtQ[m, 0]

Rubi steps \begin{align*} \text {integral}& = \frac {d (a+b \tan (e+f x))^2}{2 f}+\int (a+b \tan (e+f x)) (a c-b d+(b c+a d) \tan (e+f x)) \, dx \\ & = \left (a^2 c-b^2 c-2 a b d\right ) x+\frac {b (b c+a d) \tan (e+f x)}{f}+\frac {d (a+b \tan (e+f x))^2}{2 f}+\left (2 a b c+a^2 d-b^2 d\right ) \int \tan (e+f x) \, dx \\ & = \left (a^2 c-b^2 c-2 a b d\right ) x-\frac {\left (2 a b c+a^2 d-b^2 d\right ) \log (\cos (e+f x))}{f}+\frac {b (b c+a d) \tan (e+f x)}{f}+\frac {d (a+b \tan (e+f x))^2}{2 f} \\ \end{align*}

Mathematica [C] (verified)

Result contains complex when optimal does not.

Time = 0.48 (sec) , antiderivative size = 96, normalized size of antiderivative = 1.10 \[ \int (a+b \tan (e+f x))^2 (c+d \tan (e+f x)) \, dx=\frac {(a+i b)^2 (-i c+d) \log (i-\tan (e+f x))+(a-i b)^2 (i c+d) \log (i+\tan (e+f x))+2 b (b c+2 a d) \tan (e+f x)+b^2 d \tan ^2(e+f x)}{2 f} \]

[In]

Integrate[(a + b*Tan[e + f*x])^2*(c + d*Tan[e + f*x]),x]

[Out]

((a + I*b)^2*((-I)*c + d)*Log[I - Tan[e + f*x]] + (a - I*b)^2*(I*c + d)*Log[I + Tan[e + f*x]] + 2*b*(b*c + 2*a
*d)*Tan[e + f*x] + b^2*d*Tan[e + f*x]^2)/(2*f)

Maple [A] (verified)

Time = 0.19 (sec) , antiderivative size = 90, normalized size of antiderivative = 1.03

method result size
norman \(\left (a^{2} c -2 a b d -b^{2} c \right ) x +\frac {b \left (2 a d +b c \right ) \tan \left (f x +e \right )}{f}+\frac {b^{2} d \left (\tan ^{2}\left (f x +e \right )\right )}{2 f}+\frac {\left (a^{2} d +2 a b c -b^{2} d \right ) \ln \left (1+\tan ^{2}\left (f x +e \right )\right )}{2 f}\) \(90\)
derivativedivides \(\frac {\frac {b^{2} d \left (\tan ^{2}\left (f x +e \right )\right )}{2}+2 a b d \tan \left (f x +e \right )+b^{2} c \tan \left (f x +e \right )+\frac {\left (a^{2} d +2 a b c -b^{2} d \right ) \ln \left (1+\tan ^{2}\left (f x +e \right )\right )}{2}+\left (a^{2} c -2 a b d -b^{2} c \right ) \arctan \left (\tan \left (f x +e \right )\right )}{f}\) \(97\)
default \(\frac {\frac {b^{2} d \left (\tan ^{2}\left (f x +e \right )\right )}{2}+2 a b d \tan \left (f x +e \right )+b^{2} c \tan \left (f x +e \right )+\frac {\left (a^{2} d +2 a b c -b^{2} d \right ) \ln \left (1+\tan ^{2}\left (f x +e \right )\right )}{2}+\left (a^{2} c -2 a b d -b^{2} c \right ) \arctan \left (\tan \left (f x +e \right )\right )}{f}\) \(97\)
parts \(a^{2} c x +\frac {\left (2 a b d +b^{2} c \right ) \left (\tan \left (f x +e \right )-\arctan \left (\tan \left (f x +e \right )\right )\right )}{f}+\frac {\left (a^{2} d +2 a b c \right ) \ln \left (1+\tan ^{2}\left (f x +e \right )\right )}{2 f}+\frac {b^{2} d \left (\frac {\left (\tan ^{2}\left (f x +e \right )\right )}{2}-\frac {\ln \left (1+\tan ^{2}\left (f x +e \right )\right )}{2}\right )}{f}\) \(98\)
parallelrisch \(\frac {2 a^{2} c f x -4 a b d f x -2 b^{2} c f x +b^{2} d \left (\tan ^{2}\left (f x +e \right )\right )+\ln \left (1+\tan ^{2}\left (f x +e \right )\right ) a^{2} d +2 \ln \left (1+\tan ^{2}\left (f x +e \right )\right ) a b c -\ln \left (1+\tan ^{2}\left (f x +e \right )\right ) b^{2} d +4 a b d \tan \left (f x +e \right )+2 b^{2} c \tan \left (f x +e \right )}{2 f}\) \(115\)
risch \(\frac {2 i a^{2} d e}{f}+i a^{2} d x -i b^{2} d x +a^{2} c x -2 a b d x -b^{2} c x -\frac {2 i b^{2} d e}{f}+2 i a b c x +\frac {4 i a b c e}{f}+\frac {2 i b \left (2 a d \,{\mathrm e}^{2 i \left (f x +e \right )}+b c \,{\mathrm e}^{2 i \left (f x +e \right )}-i b d \,{\mathrm e}^{2 i \left (f x +e \right )}+2 a d +b c \right )}{f \left ({\mathrm e}^{2 i \left (f x +e \right )}+1\right )^{2}}-\frac {\ln \left ({\mathrm e}^{2 i \left (f x +e \right )}+1\right ) a^{2} d}{f}-\frac {2 \ln \left ({\mathrm e}^{2 i \left (f x +e \right )}+1\right ) a b c}{f}+\frac {\ln \left ({\mathrm e}^{2 i \left (f x +e \right )}+1\right ) b^{2} d}{f}\) \(204\)

[In]

int((a+b*tan(f*x+e))^2*(c+d*tan(f*x+e)),x,method=_RETURNVERBOSE)

[Out]

(a^2*c-2*a*b*d-b^2*c)*x+b*(2*a*d+b*c)/f*tan(f*x+e)+1/2*b^2*d/f*tan(f*x+e)^2+1/2*(a^2*d+2*a*b*c-b^2*d)/f*ln(1+t
an(f*x+e)^2)

Fricas [A] (verification not implemented)

none

Time = 0.25 (sec) , antiderivative size = 92, normalized size of antiderivative = 1.06 \[ \int (a+b \tan (e+f x))^2 (c+d \tan (e+f x)) \, dx=\frac {b^{2} d \tan \left (f x + e\right )^{2} - 2 \, {\left (2 \, a b d - {\left (a^{2} - b^{2}\right )} c\right )} f x - {\left (2 \, a b c + {\left (a^{2} - b^{2}\right )} d\right )} \log \left (\frac {1}{\tan \left (f x + e\right )^{2} + 1}\right ) + 2 \, {\left (b^{2} c + 2 \, a b d\right )} \tan \left (f x + e\right )}{2 \, f} \]

[In]

integrate((a+b*tan(f*x+e))^2*(c+d*tan(f*x+e)),x, algorithm="fricas")

[Out]

1/2*(b^2*d*tan(f*x + e)^2 - 2*(2*a*b*d - (a^2 - b^2)*c)*f*x - (2*a*b*c + (a^2 - b^2)*d)*log(1/(tan(f*x + e)^2
+ 1)) + 2*(b^2*c + 2*a*b*d)*tan(f*x + e))/f

Sympy [A] (verification not implemented)

Time = 0.11 (sec) , antiderivative size = 143, normalized size of antiderivative = 1.64 \[ \int (a+b \tan (e+f x))^2 (c+d \tan (e+f x)) \, dx=\begin {cases} a^{2} c x + \frac {a^{2} d \log {\left (\tan ^{2}{\left (e + f x \right )} + 1 \right )}}{2 f} + \frac {a b c \log {\left (\tan ^{2}{\left (e + f x \right )} + 1 \right )}}{f} - 2 a b d x + \frac {2 a b d \tan {\left (e + f x \right )}}{f} - b^{2} c x + \frac {b^{2} c \tan {\left (e + f x \right )}}{f} - \frac {b^{2} d \log {\left (\tan ^{2}{\left (e + f x \right )} + 1 \right )}}{2 f} + \frac {b^{2} d \tan ^{2}{\left (e + f x \right )}}{2 f} & \text {for}\: f \neq 0 \\x \left (a + b \tan {\left (e \right )}\right )^{2} \left (c + d \tan {\left (e \right )}\right ) & \text {otherwise} \end {cases} \]

[In]

integrate((a+b*tan(f*x+e))**2*(c+d*tan(f*x+e)),x)

[Out]

Piecewise((a**2*c*x + a**2*d*log(tan(e + f*x)**2 + 1)/(2*f) + a*b*c*log(tan(e + f*x)**2 + 1)/f - 2*a*b*d*x + 2
*a*b*d*tan(e + f*x)/f - b**2*c*x + b**2*c*tan(e + f*x)/f - b**2*d*log(tan(e + f*x)**2 + 1)/(2*f) + b**2*d*tan(
e + f*x)**2/(2*f), Ne(f, 0)), (x*(a + b*tan(e))**2*(c + d*tan(e)), True))

Maxima [A] (verification not implemented)

none

Time = 0.35 (sec) , antiderivative size = 92, normalized size of antiderivative = 1.06 \[ \int (a+b \tan (e+f x))^2 (c+d \tan (e+f x)) \, dx=\frac {b^{2} d \tan \left (f x + e\right )^{2} - 2 \, {\left (2 \, a b d - {\left (a^{2} - b^{2}\right )} c\right )} {\left (f x + e\right )} + {\left (2 \, a b c + {\left (a^{2} - b^{2}\right )} d\right )} \log \left (\tan \left (f x + e\right )^{2} + 1\right ) + 2 \, {\left (b^{2} c + 2 \, a b d\right )} \tan \left (f x + e\right )}{2 \, f} \]

[In]

integrate((a+b*tan(f*x+e))^2*(c+d*tan(f*x+e)),x, algorithm="maxima")

[Out]

1/2*(b^2*d*tan(f*x + e)^2 - 2*(2*a*b*d - (a^2 - b^2)*c)*(f*x + e) + (2*a*b*c + (a^2 - b^2)*d)*log(tan(f*x + e)
^2 + 1) + 2*(b^2*c + 2*a*b*d)*tan(f*x + e))/f

Giac [B] (verification not implemented)

Leaf count of result is larger than twice the leaf count of optimal. 811 vs. \(2 (85) = 170\).

Time = 0.69 (sec) , antiderivative size = 811, normalized size of antiderivative = 9.32 \[ \int (a+b \tan (e+f x))^2 (c+d \tan (e+f x)) \, dx=\text {Too large to display} \]

[In]

integrate((a+b*tan(f*x+e))^2*(c+d*tan(f*x+e)),x, algorithm="giac")

[Out]

1/2*(2*a^2*c*f*x*tan(f*x)^2*tan(e)^2 - 2*b^2*c*f*x*tan(f*x)^2*tan(e)^2 - 4*a*b*d*f*x*tan(f*x)^2*tan(e)^2 - 2*a
*b*c*log(4*(tan(f*x)^2*tan(e)^2 - 2*tan(f*x)*tan(e) + 1)/(tan(f*x)^2*tan(e)^2 + tan(f*x)^2 + tan(e)^2 + 1))*ta
n(f*x)^2*tan(e)^2 - a^2*d*log(4*(tan(f*x)^2*tan(e)^2 - 2*tan(f*x)*tan(e) + 1)/(tan(f*x)^2*tan(e)^2 + tan(f*x)^
2 + tan(e)^2 + 1))*tan(f*x)^2*tan(e)^2 + b^2*d*log(4*(tan(f*x)^2*tan(e)^2 - 2*tan(f*x)*tan(e) + 1)/(tan(f*x)^2
*tan(e)^2 + tan(f*x)^2 + tan(e)^2 + 1))*tan(f*x)^2*tan(e)^2 - 4*a^2*c*f*x*tan(f*x)*tan(e) + 4*b^2*c*f*x*tan(f*
x)*tan(e) + 8*a*b*d*f*x*tan(f*x)*tan(e) + b^2*d*tan(f*x)^2*tan(e)^2 + 4*a*b*c*log(4*(tan(f*x)^2*tan(e)^2 - 2*t
an(f*x)*tan(e) + 1)/(tan(f*x)^2*tan(e)^2 + tan(f*x)^2 + tan(e)^2 + 1))*tan(f*x)*tan(e) + 2*a^2*d*log(4*(tan(f*
x)^2*tan(e)^2 - 2*tan(f*x)*tan(e) + 1)/(tan(f*x)^2*tan(e)^2 + tan(f*x)^2 + tan(e)^2 + 1))*tan(f*x)*tan(e) - 2*
b^2*d*log(4*(tan(f*x)^2*tan(e)^2 - 2*tan(f*x)*tan(e) + 1)/(tan(f*x)^2*tan(e)^2 + tan(f*x)^2 + tan(e)^2 + 1))*t
an(f*x)*tan(e) - 2*b^2*c*tan(f*x)^2*tan(e) - 4*a*b*d*tan(f*x)^2*tan(e) - 2*b^2*c*tan(f*x)*tan(e)^2 - 4*a*b*d*t
an(f*x)*tan(e)^2 + 2*a^2*c*f*x - 2*b^2*c*f*x - 4*a*b*d*f*x + b^2*d*tan(f*x)^2 + b^2*d*tan(e)^2 - 2*a*b*c*log(4
*(tan(f*x)^2*tan(e)^2 - 2*tan(f*x)*tan(e) + 1)/(tan(f*x)^2*tan(e)^2 + tan(f*x)^2 + tan(e)^2 + 1)) - a^2*d*log(
4*(tan(f*x)^2*tan(e)^2 - 2*tan(f*x)*tan(e) + 1)/(tan(f*x)^2*tan(e)^2 + tan(f*x)^2 + tan(e)^2 + 1)) + b^2*d*log
(4*(tan(f*x)^2*tan(e)^2 - 2*tan(f*x)*tan(e) + 1)/(tan(f*x)^2*tan(e)^2 + tan(f*x)^2 + tan(e)^2 + 1)) + 2*b^2*c*
tan(f*x) + 4*a*b*d*tan(f*x) + 2*b^2*c*tan(e) + 4*a*b*d*tan(e) + b^2*d)/(f*tan(f*x)^2*tan(e)^2 - 2*f*tan(f*x)*t
an(e) + f)

Mupad [B] (verification not implemented)

Time = 6.22 (sec) , antiderivative size = 91, normalized size of antiderivative = 1.05 \[ \int (a+b \tan (e+f x))^2 (c+d \tan (e+f x)) \, dx=\frac {\mathrm {tan}\left (e+f\,x\right )\,\left (c\,b^2+2\,a\,d\,b\right )}{f}-x\,\left (-c\,a^2+2\,d\,a\,b+c\,b^2\right )+\frac {\ln \left ({\mathrm {tan}\left (e+f\,x\right )}^2+1\right )\,\left (\frac {d\,a^2}{2}+c\,a\,b-\frac {d\,b^2}{2}\right )}{f}+\frac {b^2\,d\,{\mathrm {tan}\left (e+f\,x\right )}^2}{2\,f} \]

[In]

int((a + b*tan(e + f*x))^2*(c + d*tan(e + f*x)),x)

[Out]

(tan(e + f*x)*(b^2*c + 2*a*b*d))/f - x*(b^2*c - a^2*c + 2*a*b*d) + (log(tan(e + f*x)^2 + 1)*((a^2*d)/2 - (b^2*
d)/2 + a*b*c))/f + (b^2*d*tan(e + f*x)^2)/(2*f)